/*
	Problem 185: Number Mind

	The game Number Mind is a variant of the well known game Master Mind.
	Instead of coloured pegs, you have to guess a secret sequence of digits. After each guess you're only told in how many places you've guessed the correct digit. So, if the sequence was 1234 and you guessed 2036, you'd be told that you have one correct digit; however, you would NOT be told that you also have another digit in the wrong place.
	For instance, given the following guesses for a 5-digit secret sequence,

	90342 ;2 correct
	70794 ;0 correct
	39458 ;2 correct
	34109 ;1 correct
	51545 ;2 correct
	12531 ;1 correct

	The correct sequence 39542 is unique.
	Based on the following guesses,

	5616185650518293 ;2 correct
	3847439647293047 ;1 correct
	5855462940810587 ;3 correct
	9742855507068353 ;3 correct
	4296849643607543 ;3 correct
	3174248439465858 ;1 correct
	4513559094146117 ;2 correct
	7890971548908067 ;3 correct
	8157356344118483 ;1 correct
	2615250744386899 ;2 correct
	8690095851526254 ;3 correct
	6375711915077050 ;1 correct
	6913859173121360 ;1 correct
	6442889055042768 ;2 correct
	2321386104303845 ;0 correct
	2326509471271448 ;2 correct
	5251583379644322 ;2 correct
	1748270476758276 ;3 correct
	4895722652190306 ;1 correct
	3041631117224635 ;3 correct
	1841236454324589 ;3 correct
	2659862637316867 ;2 correct

	Find the unique 16-digit secret sequence.
*/
package main

import (
	"fmt"
)

var (
	GS = [22][17]int{
		{5, 6, 1, 6, 1, 8, 5, 6, 5, 0, 5, 1, 8, 2, 9, 3, 2},
		{3, 8, 4, 7, 4, 3, 9, 6, 4, 7, 2, 9, 3, 0, 4, 7, 1},
		{5, 8, 5, 5, 4, 6, 2, 9, 4, 0, 8, 1, 0, 5, 8, 7, 3},
		{9, 7, 4, 2, 8, 5, 5, 5, 0, 7, 0, 6, 8, 3, 5, 3, 3},
		{4, 2, 9, 6, 8, 4, 9, 6, 4, 3, 6, 0, 7, 5, 4, 3, 3},
		{3, 1, 7, 4, 2, 4, 8, 4, 3, 9, 4, 6, 5, 8, 5, 8, 1},
		{4, 5, 1, 3, 5, 5, 9, 0, 9, 4, 1, 4, 6, 1, 1, 7, 2},
		{7, 8, 9, 0, 9, 7, 1, 5, 4, 8, 9, 0, 8, 0, 6, 7, 3},
		{8, 1, 5, 7, 3, 5, 6, 3, 4, 4, 1, 1, 8, 4, 8, 3, 1},
		{2, 6, 1, 5, 2, 5, 0, 7, 4, 4, 3, 8, 6, 8, 9, 9, 2},
		{8, 6, 9, 0, 0, 9, 5, 8, 5, 1, 5, 2, 6, 2, 5, 4, 3},
		{6, 3, 7, 5, 7, 1, 1, 9, 1, 5, 0, 7, 7, 0, 5, 0, 1},
		{6, 9, 1, 3, 8, 5, 9, 1, 7, 3, 1, 2, 1, 3, 6, 0, 1},
		{6, 4, 4, 2, 8, 8, 9, 0, 5, 5, 0, 4, 2, 7, 6, 8, 2},
		{2, 3, 2, 1, 3, 8, 6, 1, 0, 4, 3, 0, 3, 8, 4, 5, 0},
		{2, 3, 2, 6, 5, 0, 9, 4, 7, 1, 2, 7, 1, 4, 4, 8, 2},
		{5, 2, 5, 1, 5, 8, 3, 3, 7, 9, 6, 4, 4, 3, 2, 2, 2},
		{1, 7, 4, 8, 2, 7, 0, 4, 7, 6, 7, 5, 8, 2, 7, 6, 3},
		{4, 8, 9, 5, 7, 2, 2, 6, 5, 2, 1, 9, 0, 3, 0, 6, 1},
		{3, 0, 4, 1, 6, 3, 1, 1, 1, 7, 2, 2, 4, 6, 3, 5, 3},
		{1, 8, 4, 1, 2, 3, 6, 4, 5, 4, 3, 2, 4, 5, 8, 9, 3},
		{2, 6, 5, 9, 8, 6, 2, 6, 3, 7, 3, 1, 6, 8, 6, 7, 2},
	}

	likelihood = [16][10]float64{}
	guess      = [16]int{}
)

func callikelihood() {
	for i := 0; i < 16; i++ {
		for j := 0; j < 10; j++ {
			likelihood[i][j] = 0.1
		}
	}
	for i := 0; i < 22; i++ {
		if i == 14 {
			continue
		}
		del := 0
		for j := 0; j < 16; j++ {
			if GS[i][j] == GS[14][j] {
				likelihood[j][GS[i][j]] = 0
				GS[i][j] = -1
				del++
			}
		}
		for j := 0; j < 16; j++ {
			if GS[i][j] != -1 {
				likelihood[j][GS[i][j]] += float64(GS[i][16]) / float64(16-del)
			}
		}
	}
}
func getGuess() {
	for i := 0; i < 16; i++ {
		maxL := 0.0
		maxJ := -1
		for j := 0; j < 10; j++ {
			if likelihood[i][j] > maxL {
				maxL = likelihood[i][j]
				maxJ = j
			}
		}
		guess[i] = maxJ

	}
}
func P185() {
	callikelihood()
	//fmt.Println(GS)
	//fmt.Println(likelihood)
	getGuess()
	fmt.Println(guess)
	fmt.Println("Problem 185:")
}
